package com.gistmap.service.impl;

import com.gistmap.bean.Activity;
import com.gistmap.dao.ActivityDao;
import com.gistmap.dao.UserDao;
import com.gistmap.dto.ActivityDto;
import com.gistmap.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/4/17.
 */
@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityDao activityDao;
    @Autowired
    private UserDao userDao;
    public Integer save(Activity activity) {
        return activityDao.save(activity);
    }

    @Transactional
    public void join(Map map,Map map1) {
        Object obj = map.get("act_id");
        Integer id = Integer.parseInt(obj==null?"":obj.toString());
        //加入参加人到t_act_user
        activityDao.join(map);
        //活动表当前人数+1
        activityDao.addCount(id);
        //为活动创建者设置新消息
        Object biid = map1.get("bid");
        Integer bid = Integer.parseInt(biid==null?"":biid.toString());
        userDao.addMessage(bid);
        //把参加事件放到记录表
        userDao.saveAction(map1);


    }
    @Transactional
    public void joinSelf(Map map) {
        Object obj = map.get("act_id");
        Integer id = Integer.parseInt(obj==null?"":obj.toString());
        System.out.println("service***********"+map);
        System.out.println("service***********"+id);
        map.put("act_id",id);
        //加入参加人到t_act_user
        activityDao.join(map);
        //活动表当前人数+1
        activityDao.addCount(id);
    }

    public List<ActivityDto> showAct(Map<String, Object> map) {
        return activityDao.showAct(map);
    }

    public List<Integer> getJoinInfo(Integer uid) {
        return activityDao.getJoinInfo(uid);
    }

    public List<ActivityDto> showVisit(Integer uid) {
        return activityDao.showVisit(uid);
    }

    public List<ActivityDto> getJoinAct(Integer uid) {
        return activityDao.getJoinAct(uid);
    }

    public List<ActivityDto> allActs() {
        return activityDao.allActs();
    }

    public int findId(String title) {
        return activityDao.findId(title);
    }


}
